package doh.service;

import doh.logic.*;
import java.util.Vector;
import javax.ejb.Stateless;

/**
 *
 * @author davidsass
 */

@Stateless
public class RequestGameBean implements RequestGame
{
    static boolean playerAwaiting = false;
    static String awaitingPlayer;

    static Vector games = new Vector();
    static int gameID = -1;

    public int matchPlayer(String player)
    {
        
        if(playerAwaiting == false)
        {
            playerAwaiting = true;
            awaitingPlayer = player;
            while(playerAwaiting);   
            return gameID;
        }

        else
        {
            System.out.println("\n\nPlayer1: " + awaitingPlayer + "\nPlayer2: " + player + "\n\n");
            games.add( new GameSession(awaitingPlayer, player) );
            gameID++;
            playerAwaiting = false;
            return gameID;
        }
        
    }

    public void throwObject(String player, int obj, int gameID)
    {
        //((GameSession)(games.get(gameID))).throwObject(player, obj);
        System.out.println("Game ID is: " + gameID);
        ((GameSession)(games.get(0))).throwObject(player, obj);
        System.out.println("Object was thrown");
    }

    

}
